package com.zb.controller;


import com.zb.entity.dto.VersionDto;
import com.zb.entity.dto.VersionSelectDto;
import com.zb.result.Result;
import com.zb.service.ZjAdmVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 后台系统版本表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-07-12
 */
@Api(tags = "版本类接口")
@RestController
@RequestMapping("/version")
public class ZjAdmVersionController {
    @Autowired
    private ZjAdmVersionService versionService;

    @ApiOperation("新增或修改版本")
    @PostMapping("/save")
    public Result save(@RequestBody @Valid VersionDto versionDto) {
        versionService.save(versionDto);
        return Result.success(null == versionDto.getId()? "新增版本成功" : "更改版本成功");
    }

    @ApiOperation("版本列表查询")
    @PostMapping("/getList")
    public Result getList(@RequestBody VersionSelectDto selectDto) {
        return Result.success("获取版本列表成功").data(versionService.getList(selectDto));
    }

    @ApiOperation("获取版本信息")
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable @ApiParam(value = "版本ID", required = true) Long id) {
        return Result.success("获取版本信息成功").data("row", versionService.getInfoById(id));
    }

    @ApiOperation("批量禁用或启用版本")
    @PostMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "是否禁用：false-否，true-是", required = true) boolean disable,
                          @RequestBody @ApiParam(value = "版本ID集合", required = true) List<Long> idList) {
        versionService.updateBatchDisableById(idList, disable);
        return Result.success(disable? "禁用版本成功" : "启用版本成功");
    }

}
